﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ProgNetComponents.Classes;

namespace BuildHelper.Work.Template
{
    public partial class JavaTemplateForm : BaseTemplateForm
    {
        public JavaTemplateForm()
        {
            InitializeComponent();
        }
        public JavaTemplateForm(string template)
            : base(template)
        {
            InitializeComponent();
        }
        

        private void templateControl1_ReadingTemplate(object sender, Template.MergingDataSetEventArgs e)
        {
            foreach (DataRow r in javaDataSet.BUILD.Rows)
            {
                changeDetectorProvider1.CheckChanges(r, r["Buduj"], false);
                r["Buduj"] = false;
                if (r["STM"].AsString() != "GCM")
                {
                    changeDetectorProvider1.CheckChanges(r, r["Pakuj"], false);
                    r["Pakuj"] = false;
                }
            }
            this.javaDataSet.GCM_SETTINGS.Clear();
        }
        protected override void ReadTemplate()
        {
            base.ReadTemplate();
            templateControl1_TemplateRead(null, null);
        }
        private void templateControl1_TemplateRead(object sender, EventArgs e)
        {
            foreach (var r in javaDataSet.BUILD)
            {
                if (r.IsGENERATEDNull())
                    r.GENERATED = false;
                if (r.IsPackWSNull())
                    r.PackWS = false;
            }
            
            if (javaDataSet.GCM_SETTINGS.Rows.Count == 0)
            {
                var r = javaDataSet.GCM_SETTINGS.NewRow();
                javaDataSet.GCM_SETTINGS.Rows.Add(r);
            }
            if (javaDataSet.GCM_SETTINGS.Rows.Count > 0)
            {
                foreach (DataColumn c in javaDataSet.GCM_SETTINGS.Columns)
                {
                    if (javaDataSet.GCM_SETTINGS.Rows[0][c].IsNull())
                        javaDataSet.GCM_SETTINGS.Rows[0][c] = false;
                }
            }
        }
        private void lueBrancz_EditValueChanged(object sender, EventArgs e)
        {
            ReadBranch(lueBrancz.EditValue.AsString());
        }
        private void ReadBranch(string brancz)
        {
            changeDetectorProvider1.SetModified();
            javaDataSet.Clear();
            JAVA.BudowanieJavyTools.ReadBranch(brancz, javaDataSet);
        }
    }
}
